#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <cmath>

bool isPrime(int num) {
    if (num <= 1) return false;
    if (num == 2) return true;
    if (num % 2 == 0) return false;
    for (int i = 3; i <= std::sqrt(num); i += 2) {
        if (num % i == 0) return false;
    }
    return true;
}

int nearestPrime(int n) {
    int lower = n, upper = n;
    while (true) {
        if (lower > 1 && isPrime(lower)) return lower;
        if (isPrime(upper)) return upper;
        lower--;
        upper++;
    }
}

int main() {
    std::unordered_map<std::string, int> num_dict = {
        {"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3}, {"four", 4},
        {"five", 5}, {"six", 6}, {"seven", 7}, {"eight", 8}, {"nine", 9}
    };

    std::vector<std::string> words;
    std::string word;

    while (std::cin >> word) {
        words.push_back(word);
        if (words.size() == 3) break;
    }

    if (words.size() != 3) {
        std::cout << "Wrong input" << std::endl;
        return 0;
    }

    try {
        int digits[3];
        for (int i = 0; i < 3; ++i) {
            digits[i] = num_dict.at(words[i]);
        }

        int number = digits[0] * 100 + digits[1] * 10 + digits[2];

        if (number < 100 || number > 999) {
            std::cout << "Wrong input" << std::endl;
        } else {
            std::cout << nearestPrime(number) << std::endl;
        }
    } catch (const std::out_of_range&) {
        std::cout << "Wrong input" << std::endl;
    }

    return 0;
}
